
package com.lenovo.vctlclient.util;

/**
 * @author wangxiang 2012-7-11
 */
public class Log {

    public static String TAG = "Weaver";

    private static int LOG_LEVEL = 5;

    public static void setLogLevel(int level) {
        LOG_LEVEL = level;
    }

    public static void v(String location, String msg) {
        if (LOG_LEVEL >= 5) {
            android.util.Log.v(TAG, buildLog(location, msg));
        }
    }

    public static void v(String location, String msg, Throwable tr) {
        if (LOG_LEVEL >= 5) {
            android.util.Log.v(TAG, buildLog(location, msg), tr);
        }
    }

    public static void d(String location, String msg) {
        if (LOG_LEVEL >= 4) {
            android.util.Log.d(TAG, buildLog(location, msg));
        }
    }

    public static void d(String location, String msg, Throwable tr) {
        if (LOG_LEVEL >= 4) {
            android.util.Log.d(TAG, buildLog(location, msg), tr);
        }
    }

    public static void i(String location, String msg) {
        if (LOG_LEVEL >= 3) {
            android.util.Log.i(TAG, buildLog(location, msg));
        }
    }

    static void i(String location, String msg, Throwable tr) {
        if (LOG_LEVEL >= 3) {
            android.util.Log.i(TAG, buildLog(location, msg), tr);
        }
    }

    public static void w(String location, String msg) {
        if (LOG_LEVEL >= 2) {
            android.util.Log.w(TAG, buildLog(location, msg));
        }
    }

    public static void w(String location, String msg, Throwable tr) {
        if (LOG_LEVEL >= 2) {
            android.util.Log.w(TAG, buildLog(location, msg), tr);
        }
    }

    public static void e(String location, String msg) {
        if (LOG_LEVEL >= 1) {
            android.util.Log.e(TAG, buildLog(location, msg));
        }
    }

    public static void e(String location, String msg, Throwable tr) {
        if (LOG_LEVEL >= 1) {
            android.util.Log.e(TAG, buildLog(location, msg), tr);
        }
    }

    private static String buildLog(String location, String msg) {
        return new StringBuffer().append("|").append(location).append("|").append(msg).toString();
    }

}
